<?php

namespace App\Http\Controllers\api;

use App\Order;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Venue;

class OrderController extends Controller
{

   // 登录用户订单列表
   public function list(){

       // 获取登录用户
       $user = \Auth::guard('api')->user();
       $orders = $user->my_orders()->paginate(2);
       foreach($orders as $k=>$order){
           $orders[$k]['venue'] = Venue::find($order->venue_id);
       }
       return $orders;
       
   }


    //保存订单数据
    public function save(Request $request){

    

        foreach($request->items as $item){

            $order = new Order();
            $order->user_id = \Auth::id();
            $order->venue_id = $request->venue_id;
            $order->order_date = $request->order_date;
            
            $order->sn = $item["sn"];
            $order->time = $item["time"];

            $order->save();

        }

        return response()->json(["status"=>200,'msg'=>'订单保存成功!']);
    
    }
}
